package cn.zz.veggie.web.controller.mgmt;

import java.util.List;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.zz.comm.core.types.IdNameObj;
import cn.zz.comm.core.types.query.PageQuery;
import cn.zz.comm.core.types.result.PageResult;
import cn.zz.comm.web.annotation.BoxRespResult;
import cn.zz.veggie.application.service.ShopAppService;
import cn.zz.veggie.web.types.dto.mgmt.shop.MgmtShopQueryDto;
import cn.zz.veggie.web.types.dto.mgmt.shop.MgmtShopSaveDto;
import cn.zz.veggie.web.types.vo.mgmt.shop.MgmtShopVo;
import jakarta.validation.constraints.Positive;
import lombok.RequiredArgsConstructor;

/**
 * @author zhongq
 * @since 2024/7/26
 */
@Validated
@BoxRespResult
@RestController
@RequiredArgsConstructor
@RequestMapping("/mgmt/shop")
public class MgmtShopController {
	private final ShopAppService shopAppService;

	/**
	 * 输入框搜索
	 */
	@GetMapping("/search")
	public List<IdNameObj> searchShop(String keyword) {
		return shopAppService.mgmtShopSearch(keyword);
	}

	@GetMapping("/list")
	public PageResult<MgmtShopVo> findShops(@RequestParam(defaultValue = "1") @Positive Integer current,
											@RequestParam(defaultValue = "10") @Positive Integer size, @Validated MgmtShopQueryDto dto) {
		return shopAppService.mgmtFindShops(dto, PageQuery.of(current, size));
	}

	@PostMapping("/save")
	public void saveShop(@RequestBody @Validated MgmtShopSaveDto dto) {
		shopAppService.mgmtSaveShop(dto);
	}

	@DeleteMapping("/remove")
	public void removeShop(@RequestParam @Positive Integer id) {
		shopAppService.mgmtRemoveShop(id);
	}

}